package com.ahdy.mapper;

import com.ahdy.entity.GoodPeople;
import org.apache.ibatis.annotations.*;

import java.util.List;

// 好人Mapper接口
@Mapper
public interface GoodPeopleMapper {

    // 基础CRUD操作
    @Insert("INSERT INTO good_people(phone, password, name, elderly_id, thing, create_time, end_time) " +
            "VALUES(#{phone}, #{password}, #{name}, #{elderlyId}, #{thing}, #{createTime}, #{endTime})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(GoodPeople goodPeople);

    @Update("UPDATE good_people SET phone=#{phone}, password=#{password}, name=#{name}, " +
            "elderly_id=#{elderlyId}, thing=#{thing}, create_time=#{createTime}, end_time=#{endTime} " +
            "WHERE id=#{id}")
    int update(GoodPeople goodPeople);

    @Delete("DELETE FROM good_people WHERE id=#{id}")
    int deleteById(Integer id);

    @Select("SELECT * FROM good_people WHERE id=#{id}")
    GoodPeople findById(Integer id);

    @Select("SELECT * FROM good_people")
    List<GoodPeople> findAll();

    // 业务查询方法
    @Select("SELECT * FROM good_people WHERE phone=#{phone}")
    GoodPeople findByPhone(String phone);

    @Select("SELECT * FROM good_people WHERE phone=#{phone} AND password=#{password}")
    GoodPeople findByPhoneAndPassword(@Param("phone") String phone, @Param("password") String password);

    @Select("SELECT * FROM good_people WHERE elderly_id=#{elderlyId}")
    List<GoodPeople> findByElderlyId(Integer elderlyId);

    @Select("SELECT * FROM good_people WHERE thing=#{thing}")
    List<GoodPeople> findByThing(String thing);
} 